﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace QLThuVien
{
    public partial class frQL : Form
    {
        public frQL()
        {
            InitializeComponent();
        }
        public static NhanVien nv = new NhanVien();
        public static frdn dn = new frdn();

        private void đăngNhậpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frQL_Load(null, null);
            Hide();
        }
        private void frQL_Load(object sender, EventArgs e)
        {
            dn = new frdn();
            dn.ShowDialog();
            if (dn.DialogResult == DialogResult.OK)
            {
                StreamWriter sw = new StreamWriter("luu nhan vien.txt");
                sw.WriteLine(frdn.kt.get_manv());
                sw.Close();
                StreamWriter sw1 = new StreamWriter("luu password.txt");
                sw1.WriteLine(frdn.kt.get_matkhau());
                sw1.Close();
                nv = new NhanVien(frdn.kt.get_manv(), frdn.kt.get_hoten(), frdn.kt.get_diachi(), frdn.kt.get_quyenhan(), frdn.kt.get_tendangnhap(), frdn.kt.get_matkhau());
            }
            if (frdn.kt.get_quyenhan().Equals("ADMIN", StringComparison.CurrentCultureIgnoreCase))
            {
                QuanLyDanhMuc.Enabled = true;
                QuanLyDocGia.Enabled = true;
                QuanLySach.Enabled = true;
                QuanLyMuonTra.Enabled = true;
                QuanLyNhanVien.Enabled = true;
                DangXuat.Enabled = true;
                DangNhap.Enabled = false;
                ThayDoiMatKhau.Enabled = true;
                QuanLyThongKe.Enabled = true;
            }

            else if (frdn.kt.get_quyenhan().Equals("MUONTRA", StringComparison.CurrentCultureIgnoreCase))
            {
                QuanLyDanhMuc.Enabled = false;
                QuanLyDocGia.Enabled = false;
                QuanLySach.Enabled = false;
                QuanLyMuonTra.Enabled = true;
                QuanLyNhanVien.Enabled = false;
                DangXuat.Enabled = true;
                DangNhap.Enabled = false;
                ThayDoiMatKhau.Enabled = true;
                QuanLyThongKe.Enabled = true;
            }

            else if (frdn.kt.get_quyenhan().Equals("THUKHO", StringComparison.CurrentCultureIgnoreCase))
            {
                QuanLyDanhMuc.Enabled = true;
                QuanLyDocGia.Enabled = false;
                QuanLySach.Enabled = true;
                QuanLyMuonTra.Enabled = false;
                QuanLyNhanVien.Enabled = false;
                DangXuat.Enabled = true;
                DangNhap.Enabled = false;
                QuanLyThongKe.Enabled = true;
                ThayDoiMatKhau.Enabled = true;
            }
            else
            {
                QuanLyDanhMuc.Enabled = false;
                QuanLyDocGia.Enabled = false;
                QuanLySach.Enabled = false;
                QuanLyMuonTra.Enabled = false;
                QuanLyNhanVien.Enabled = false;
                DangXuat.Enabled = false;
                DangNhap.Enabled = true;
                ThayDoiMatKhau.Enabled = false;
                QuanLyThongKe.Enabled = false;
            }
        }

        private void DangXuat_Click(object sender, EventArgs e)
        {
            
            QuanLyDanhMuc.Enabled = false;
            QuanLyDocGia.Enabled = false;
            QuanLySach.Enabled = false;
            QuanLyMuonTra.Enabled = false;
            QuanLyNhanVien.Enabled = false;
            DangXuat.Enabled = false;
            DangNhap.Enabled = true;
            ThayDoiMatKhau.Enabled = false;
            QuanLyThongKe.Enabled = false;
        }

        private void QuanLyNhanVien_Click(object sender, EventArgs e)
        {
            frQLNV frnv = new frQLNV();
            frnv.Show();
        }

        private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void ThayDoiMatKhau_Click(object sender, EventArgs e)
        {
            frthaydoimatkhau frtdmk = new frthaydoimatkhau();
            frtdmk.ShowDialog();
        }

        private void quảnLýMượnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frMuonSach frms = new frMuonSach();
            frms.Show();
        }

        private void quảnLýTrảToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frTraSach frts = new frTraSach();
            frts.Show();
        }

        private void QuanLyDanhMuc_Click(object sender, EventArgs e)
        {
            frDanhMuc frdm = new frDanhMuc();
            frdm.Show();
        }

        private void cậpNhậtSáchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frCapNhatSach frcns = new frCapNhatSach();
            frcns.Show();
        }

        private void tìmKiếmSáchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frTimKiemSach frtks = new frTimKiemSach();
            frtks.Show();
        }

        private void cậpNhậtĐộcGiảToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frThongTinDocGia frttdg = new frThongTinDocGia();
            frttdg.Show();
        }

        private void tìmKiếmĐộcGiảToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frTimKiemDocGia frtkdg = new frTimKiemDocGia();
            frtkdg.Show();
        }

        private void danhSáchMượnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frDanhSachMuon frdsm = new frDanhSachMuon();
            frdsm.Show();
        }

        private void sáchCònTrongThưViệnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frSachConTrongThuVien frscttv = new frSachConTrongThuVien();
            frscttv.Show();
        }

        
    }
}
